#include <conio.h>
#include "cli.h"
#include "vectr.h"

#include <iostream>
using namespace std;

struct DBMonsterTemplate
{
	char * typeName;	// EG murloc, orc, ogre
	int level;
	int maxHP;
	char * personality;
	int atk;
	int def;
	char icon;
	DBMonsterTemplate(char * n, int l, int h, char * p, int a, int d, char i)
		:typeName(n), level(l), maxHP(h), personality(p), atk(a), def(d), icon(i){}
};

struct Item
{
	int worth;
	Item(int w):worth(w){}
};

struct DBMonsterInstance
{
	DBMonsterTemplate * type;
	char * name;
	int currentHP;
	int currentAtk;
	int currentDef;
	char ** items;
	int numItems;
	int x, y;
	DBMonsterInstance(DBMonsterTemplate * t, char * n, int x, int y)
		:type(t), name(n), x(x), y(y)
	{
		currentHP = t->maxHP;
		currentAtk = t->atk;
		currentDef = t->def;
		items = NULL;
		numItems = 0;
	}
};

// name value pair
struct DBMonsterAlias
{
	char * alias;
	DBMonsterTemplate * type;

	DBMonsterAlias(char * alias, DBMonsterTemplate * type)
		:alias(alias), type(type){}
};

DBMonsterTemplate * getType(char * name, Vectr & types, Vectr * aliases)
{
	DBMonsterTemplate * t;
	for(int i = 0; i < types.getSize(); ++i)
	{
		t = (DBMonsterTemplate*)types.get(i);
		if(strcmp(t->typeName, name) == 0)
		{
			return t;
		}
	}
	if(aliases != NULL)
	{
		DBMonsterAlias * a;
		for(int i = 0; i < aliases->getSize(); ++i)
		{
			a = (DBMonsterAlias*)aliases->get(i);
			if(strcmp(a->alias, name) == 0)
			{
				return a->type;
			}
		}
	}
	return NULL;
}

int main()
{
//	DBMonsterTemplate ** types = new DBMonsterTemplate * [4];
	Vectr types;
	types.add(new DBMonsterTemplate("human", 0, 10, "friendly", 1, 1, 1));
	types.add(new DBMonsterTemplate("orc", 1, 12, "angry", 2, 0, 2));
	types.add(new DBMonsterTemplate("slug", 4, 30, "slimy", 0, 4, 'S'));
	types.add(new DBMonsterTemplate("dragon", 10, 100, "dragon", 10, 10, 'D'));

	Vectr aliases;
	aliases.add(new DBMonsterAlias("person", getType("human", types, NULL)));
	aliases.add(new DBMonsterAlias("guy", getType("human", types, NULL)));
	aliases.add(new DBMonsterAlias("gal", getType("human", types, NULL)));
	aliases.add(new DBMonsterAlias("dire slug", getType("slug", types, NULL)));
	aliases.add(new DBMonsterAlias("DRAGON", getType("dragon", types, NULL)));

	DBMonsterInstance ** monsterList = new DBMonsterInstance *[7];
	monsterList[0] = new DBMonsterInstance(getType("human", types, &aliases), "bob", 0,0);
	monsterList[1] = new DBMonsterInstance(getType("person", types, &aliases), "jill", 2,1);
	monsterList[2] = new DBMonsterInstance(getType("orc", types, &aliases), "rognob", 2,8);
	monsterList[3] = new DBMonsterInstance(getType("slug", types, &aliases), "sluggo", 5,5);
	monsterList[4] = new DBMonsterInstance(getType("dire slug", types, &aliases), "swishy", 4,6);
	monsterList[5] = new DBMonsterInstance(getType("slug", types, &aliases), "oggles", 6,4);
	monsterList[6] = new DBMonsterInstance(getType("dragon", types, &aliases), "ZORIDOSIXADAR", 10,10);

	char input;
	int height = 15;
	int width = 25;
	do
	{
		gotoxy(0,0);
		for(int r = 0; r < height; ++r)
		{
			for(int c = 0; c < width; ++c)
			{
				cout << ".";
			}
			cout << endl;
		}

		for(int i = 0; i < 7; ++i)
		{
			gotoxy(monsterList[i]->x, monsterList[i]->y);
			cout << monsterList[i]->type->icon;
		}
		input = getch();
	}
	while(input != 'q');

	return 0;
}